<?php
$viewDate = null;

//CRUD functions
if (isset($_POST['action'])) {

   $viewDate = $_SESSION['viewDate'];

   switch ($_POST['action']) {
      case 'Save':
         $resultsUpdateShift = modifyShift(
                 $_SESSION['userName'], $_SESSION['userName'], $_POST['roleID'], $_POST['dateID'], $_POST['empID'], $_POST['fieldToModify'], $_POST['newValue']);
         break;
      case 'Delete Shift':
         $resultsRemoveShift = removeShift($_SESSION['userName'], $_SESSION['userPassHash'], $_POST['roleID'], $_POST['dateID'], $_POST['empID']);
         break;
   }
}
//CRUD functions

if ($viewDate == null) {
   if (isset($_POST['viewDate'])) {
      $_SESSION['viewDate'] = $viewDate = $_POST['viewDate'];
   } else {
      $_SESSION['viewDate'] = $viewDate = date("Y-m-d");
   }
}

$viewDate = strtotime($viewDate);
?>

<form action="" method="post">
   <input type="date" name="viewDate" value="<?php echo(date("Y-m-d", $viewDate)); ?>" />
   <input type="submit" name="dateRange" value="View Surrounding Week" />
   <input type="submit" name="dateRange" value="View Day" />
</form>

<?php
$dateRange;
if (isset($_POST['dateRange'])) {
   $dateRange = $_POST['dateRange'];
   $_SESSION['dateRange'] = $dateRange;
} elseif (isset($_SESSION['dateRange'])) {
   $dateRange = $_SESSION['dateRange'];
} else {
   $dateRange = "View Surrounding Week";
}

switch ($dateRange) {
   case "View Day":
      include_once "main_shiftManagerDaily.php";
      break;
   case "View Surrounding Week":
   default:
      include_once "main_shiftManagerWeekly.php";
      break;
}
?>